package com.itheima.shengxiao;

public class Foodie implements Runnable {


    @Override
    public void run() {
        //死循环
        while (true){

            synchronized (Desk.obj){
                if(Desk.count==0){
                    break;
                }
                if(!Desk.fan){ // 判断桌上是否有饭
                    //没有饭  等着
                    try {
                        Desk.obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else {
                    //有饭 吃饭
                    System.out.println("吃货正在吃一碗饭");
                    //更改桌子上饭的装态
                    Desk.fan=false;
                    //总量-1
                    Desk.count--;
                    //叫厨子继续做
                    Desk.obj.notifyAll();
                }
            }
        }
    }
}
